home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Expanders / MultiList / funcs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  9.9 KB  |  398 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/nodes.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/memory.h>
  7. #include <exec/types.h>
  8. #include <dos/dos.h>                    // dos
  9. #include <intuition/intuition.h>        // intuition
  10. #include <clib/exec_protos.h>           // protos
  11. #include <clib/dos_protos.h>
  12. #include <clib/gadtools_protos.h>
  13. #include <pragmas/exec_pragmas.h>       // pragmas
  14. #include <pragmas/dos_pragmas.h>
  15. #include <pragmas/graphics_pragmas.h>
  16. #include <pragmas/gadtools_pragmas.h>
  17.  
  18. #include <stdarg.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <ctype.h>
  23.  
  24. #include "DEV_IE:Expanders/defs.h"
  25. ///
  26. /// Prototypes
  27. /* we use a cut-down version of the ObjectInfo */
  28. struct ObjectInfo {
  29.     struct  Node    Node;
  30.     UWORD           Kind;
  31.     UBYTE           Flags;
  32.     UBYTE           Pad;
  33.     APTR            Reserved;
  34.     UBYTE           Reserved2[80];
  35.     UBYTE           Reserved3[40];
  36.     WORD            User1;
  37.     WORD            User2;
  38.     WORD            Left;
  39.     WORD            Top;
  40.     UWORD           Width;
  41.     UWORD           Height;
  42. };
  43. ///
  44.  
  45.  
  46.  
  47. /*  Starting function           */
  48. /// IEX_Mount
  49. __geta4 ULONG IEX_Mount( __A0 struct IE_Data *IE )
  50. {
  51.     BPTR                    DescFile;
  52.     struct FileInfoBlock   *fib;
  53.     ULONG                   ret = IEX_ERROR_NO_DESC_FILE;
  54.     static UBYTE            FileName[] = "PROGDIR:Expanders/MultiList.desc";
  55.  
  56.     Forbid();   /* we're going to write to a GLOBAL variable */
  57.  
  58.     if( Desc ) {            /* already mounted? */
  59.     Permit();
  60.     return( IEX_OK );
  61.     }
  62.  
  63.     LibBase->Kind      = IEX_OBJECT_KIND;
  64.  
  65.     LibBase->Resizable = TRUE;
  66.     LibBase->Movable   = TRUE;
  67.     LibBase->HasItems  = TRUE;
  68.     LibBase->UseFonts  = TRUE;
  69.  
  70.     LibBase->Node.ln_Name = "MULTISELECT LISTVIEW";
  71.  
  72.     if( fib = AllocDosObject( DOS_FIB, NULL )) {
  73.     if( DescFile = Lock( FileName, ACCESS_READ )) {
  74.  
  75.         Examine( DescFile, fib );
  76.         UnLock( DescFile );
  77.  
  78.         if( Desc = AllocVec( fib->fib_Size, 0L )) {
  79.         if( DescFile = Open( FileName, MODE_OLDFILE )) {
  80.  
  81.             Read( DescFile, Desc, fib->fib_Size );
  82.             Close( DescFile );
  83.  
  84.             ( *IE->IEXFun->SplitLines )( Desc ); // VERY important!
  85.  
  86.             STRPTR pri;
  87.  
  88.             pri = ( *IE->IEXFun->GetFirstLine )( Desc, "RENDPRI" );
  89.  
  90.             if( pri )
  91.             LibBase->Node.ln_Pri = atoi( pri );
  92.             else
  93.             LibBase->Node.ln_Pri = 0;
  94.  
  95.             ret = IEX_OK;
  96.  
  97.         } else {
  98.             FreeVec( Desc );
  99.             Desc = NULL;
  100.         }
  101.         }
  102.  
  103.     }
  104.  
  105.     FreeDosObject( DOS_FIB, fib );
  106.     }
  107.  
  108.     Permit();
  109.  
  110.     return( ret );
  111. }
  112. ///
  113.  
  114.  
  115. /*  Edit functions              */
  116. /// IEX_Add
  117. __geta4 BOOL IEX_Add( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 WORD x, __D2 WORD y, __D3 UWORD width, __D4 UWORD height )
  118. {
  119.     struct ObjectInfo   *Object;
  120.     BOOL                ret = FALSE;
  121.  
  122.     if( Object = AllocMem( sizeof( struct ObjectInfo ), MEMF_CLEAR )) {
  123.  
  124.     Object->Kind   = ID;       /* DON'T FORGET!!! */
  125.     Object->Left   = x;
  126.     Object->Top    = y;
  127.     Object->Width  = width;
  128.     Object->Height = height;
  129.     Object->Flags  = G_ATTIVO; /* make it active  */
  130.  
  131.     /* add our object to the list */
  132.     AddTail((struct List *)&IE->win_info->wi_Gadgets, (struct Node *)Object );
  133.  
  134.     IE->win_info->wi_NumObjects += 1;
  135.  
  136.     ret = TRUE;
  137.     }
  138.  
  139.     return( ret );
  140. }
  141. ///
  142. /// IEX_Remove
  143. __geta4 void IEX_Remove( __D0 UWORD ID, __A0 struct IE_Data *IE )
  144. {
  145.     struct ObjectInfo   *Object, *next;
  146.  
  147.     for( Object = IE->win_info->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ ) {
  148.     /* remove only the objects of our kind and that are selected  */
  149.     if(( Object->Kind == ID ) && ( Object->Flags & G_ATTIVO )) {
  150.         next = Object->Node.ln_Pred;
  151.  
  152.         Remove(( struct Node * )Object );
  153.  
  154.         IE->win_info->wi_NumObjects -= 1;
  155.  
  156.         FreeMem( Object, sizeof( struct ObjectInfo ));
  157.         Object = next;
  158.     }
  159.     }
  160. }
  161. ///
  162. /// IEX_Edit
  163. __geta4 BOOL IEX_Edit( __D0 UWORD ID, __A0 struct IE_Data *IE )
  164. {
  165.     return( FALSE );
  166. }
  167. ///
  168. /// IEX_Copy
  169. __geta4 BOOL IEX_Copy( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 WORD offx, __D2 WORD offy )
  170. {
  171.     struct ObjectInfo   *Object, *copy;
  172.  
  173.     for( Object = IE->win_info->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ ) {
  174.     if(( Object->Kind == ID ) && ( Object->Flags & G_ATTIVO )) {
  175.  
  176.         if( copy = AllocMem( sizeof( struct ObjectInfo ), 0L )) {
  177.  
  178.         CopyMem((char *)Object, (char *)copy, (long)sizeof( struct ObjectInfo ));
  179.  
  180.         AddTail((struct List *)&IE->win_info->wi_Gadgets, (struct Node *)copy );
  181.  
  182.         IE->win_info->wi_NumObjects += 1; /* Don't forget! */
  183.  
  184.         copy->Left += offx;  /* update its position */
  185.         copy->Top  += offy;
  186.  
  187.         /* I don't want a neverending loop... ;-) */
  188.         copy->Flags &= ~G_ATTIVO;
  189.  
  190.         } else
  191.         return( FALSE );
  192.     }
  193.     }
  194.  
  195.     return( TRUE );
  196. }
  197. ///
  198. /// IEX_Make
  199. __geta4 struct Gadget *IEX_Make( __D0 UWORD ID, __A0 struct IE_Data *IE, __A1 struct Gadget *glist )
  200. {
  201.     /*  We don't need to make anything  */
  202.     return( glist );
  203. }
  204. ///
  205. /// IEX_Free
  206. __geta4 void IEX_Free( __D0 UWORD ID, __A0 struct IE_Data *IE )
  207. {
  208.     /*  We've got nothing to free when the window is closed  */
  209. }
  210. ///
  211. /// IEX_Refresh
  212. __geta4 void IEX_Refresh( __D0 UWORD ID, __A0 struct IE_Data *IE )
  213. {
  214.     struct ObjectInfo *Object;
  215.  
  216.     for( Object = IE->win_info->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ ) {
  217.     /*  always check the Kind  */
  218.     if( Object->Kind == ID ) {
  219.  
  220.         DrawObjectBox( IE->win_active->RPort,
  221.               Object->Left, Object->Top,
  222.               Object->Width, Object->Height,
  223.               GTBB_Recessed, TRUE,
  224.               GT_VisualInfo, IE->ScreenData->Visual, TAG_DONE );
  225.  
  226.         SetAPen( IE->win_active->RPort, 0 );
  227.         RectFill( IE->win_active->RPort,
  228.               Object->Left + 2, Object->Top + 1,
  229.               Object->Left + Object->Width  - 3,
  230.               Object->Top  + Object->Height - 2  );
  231.     }
  232.     }
  233. }
  234. ///
  235.  
  236.  
  237. /*  I/O Functions               */
  238. /// IEX_Save
  239. __geta4 void IEX_Save( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 BPTR File )
  240. {
  241.     struct ObjectInfo   *Object;
  242.  
  243.     for( Object = IE->win_info->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ )
  244.     if(( Object->Kind == ID ) && ( Object->Flags & G_ATTIVO ))
  245.         FWrite( File, &Object->Left, 8, 1 );
  246. }
  247. ///
  248. /// IEX_Load
  249. __geta4 BOOL IEX_Load( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 BPTR File, __D2 UWORD Num )
  250. {
  251.     struct ObjectInfo   *Object;
  252.     UWORD               cnt;
  253.  
  254.     for( cnt = 0; cnt < Num; cnt++ ) {
  255.     if( Object = AllocMem( sizeof( struct ObjectInfo ), MEMF_CLEAR )) {
  256.  
  257.         Object->Kind = ID;  /* VERY important!!! */
  258.  
  259.         AddTail(( struct List * )&IE->win_info->wi_Gadgets, ( struct Node * )Object );
  260.  
  261.         FRead( File, &Object->Left, 8, 1 );
  262.  
  263.     } else
  264.         return( FALSE );
  265.     }
  266.  
  267.     return( TRUE );
  268. }
  269. ///
  270.  
  271.  
  272. /*  Source related functions    */
  273. /// IEX_StartSrcGen
  274. __geta4 STRPTR IEX_StartSrcGen( __D0 UWORD ID, __A0 struct IE_Data *IE )
  275. {
  276.     struct WindowInfo  *wnd;
  277.     struct ObjectInfo   *Object;
  278.     STRPTR              func;
  279.  
  280.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  281.     if( wnd->wi_NumObjects ) {
  282.         for( Object = wnd->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ ) {
  283.         if( Object->Kind == ID )
  284.             wnd->wi_NeedRender = TRUE;
  285.         }
  286.     }
  287.     }
  288.  
  289.     func = ( IE->SrcFlags & FONTSENSITIVE ) ? "SUPPORT-FA" : "SUPPORT";
  290.  
  291.     return(( *IE->IEXFun->GetFirstLine )( Desc, func ));
  292. }
  293. ///
  294. /// IEX_WriteGlobals
  295. __geta4 void IEX_WriteGlobals( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  296. {
  297. }
  298. ///
  299. /// IEX_WriteSetup
  300. __geta4 void IEX_WriteSetup( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  301. {
  302. }
  303. ///
  304. /// IEX_WriteCloseDown
  305. __geta4 void IEX_WriteCloseDown( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  306. {
  307. }
  308. ///
  309. /// IEX_WriteHeaders
  310. __geta4 void IEX_WriteHeaders( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  311. {
  312.     STRPTR string;
  313.  
  314.     if( string = ( *IE->IEXFun->GetFirstLine )( Desc, "HEADER" ))
  315.     FPuts( Files->XDef, string );
  316. }
  317. ///
  318. /// IEX_WriteRender
  319. __geta4 void IEX_WriteRender( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  320. {
  321.     UBYTE               X[6], Y[6], Width[6], Height[6];
  322.     struct Descriptor   Dsc[] = {
  323.     { 'x', X },
  324.     { 'y', Y },
  325.     { 'W', Width },
  326.     { 'h', Height },
  327.     { 'w', IE->win_info->wi_Label },
  328.     { 'g', NULL },
  329.     { 0, NULL }
  330.     };
  331.     struct ObjectInfo   *Object;
  332.     STRPTR              String;
  333.     static UBYTE        ld[] = "%ld";
  334.  
  335.     if( IE->win_info->wi_NumObjects ) {
  336.     if( String = ( *IE->IEXFun->GetFirstLine )( Desc, IE->win_info->wi_NumBools ? "RENDER-BOOL" : "RENDER" )) {
  337.  
  338.         if( IE->win_info->wi_NumBools ) {
  339.         struct BooleanInfo *bool;
  340.  
  341.         bool = IE->win_info->wi_Gadgets.mlh_Head;
  342.  
  343.         while( bool->b_Kind != BOOLEAN )
  344.             bool = bool->b_Node.ln_Succ;
  345.  
  346.         Dsc[5].Meaning = bool->b_Label;
  347.         }
  348.  
  349.         for( Object = IE->win_info->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ ) {
  350.         if( Object->Kind == ID ) {
  351.  
  352.             sprintf( X, ld, Object->Left - IE->ScreenData->XOffset );
  353.             sprintf( Y, ld, Object->Top  - IE->ScreenData->YOffset );
  354.             sprintf( Width, ld, Object->Width );
  355.             sprintf( Height, ld, Object->Height );
  356.  
  357.             ( *IE->IEXFun->WriteFormatted )( Files->Std, String, &Dsc[0] );
  358.         }
  359.         }
  360.     }
  361.     }
  362. }
  363. ///
  364. /// IEX_GetIDCMP
  365. __geta4 ULONG IEX_GetIDCMP( __D0 UWORD ID, __D1 ULONG idcmp, __A0 struct IE_Data *IE )
  366. {
  367.     struct WindowInfo  *wnd;
  368.     struct ObjectInfo   *Object;
  369.  
  370.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  371.     for( Object = wnd->wi_Gadgets.mlh_Head; Object->Node.ln_Succ; Object = Object->Node.ln_Succ )
  372.         if( Object->Kind == ID )
  373.         return( idcmp | LISTVIEWIDCMP );
  374.  
  375.     return( idcmp );
  376. }
  377. ///
  378. /// IEX_WriteData
  379. __geta4 void IEX_WriteData( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  380. {
  381. }
  382. ///
  383. /// IEX_WriteChipData
  384. __geta4 void IEX_WriteChipData( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  385. {
  386. }
  387. ///
  388. /// IEX_WriteOpenWnd
  389. __geta4 void IEX_WriteOpenWnd( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  390. {
  391. }
  392. ///
  393. /// IEX_WriteCloseWnd
  394. __geta4 void IEX_WriteCloseWnd( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  395. {
  396. }
  397. ///
  398.